/**
 * Created by asus on 2017/5/3.
 */

/*var login_cookie = $.cookie("get", {
    name: 'Login'
});
login_cookie = $.parseJSON(login_cookie);
console.log(login_cookie);

var user_info = login_cookie.data;
$(".u_balance").html(user_info.u_balance);*/




//用户余额
var balance_param = {
    url:'Users/balance'
};
$.JsonRpc(balance_param,function(data) {
    var　u_balance_val =  data.data.u_balance.replace(/,/g,"");
    var u_balance = $(".u_balance");
    u_balance.html(u_balance_val);
});


var req = {
    url:'Recharges/buy',
    data:{
        type:10
    }
};
var rc_pay_num = $(".rc_pay_num");

$.JsonRpc(req,function(data){
    console.log(data);
    data = data.data.list;
    var tpl = "";
    $.each(data,function(i){
        var tripleClass="";
        if((i+1)%3==0){
            tripleClass="tripleBox";
        }
        tpl+=
        '<li class="'+tripleClass+'" data-c_id="'+data[i].cid+'" data-c_value="'+data[i].c_value+'" data-c_sort="'+data[i].c_sort+'">'+
        data[i].c_value+'L币'+
        '</li>';
    });

    var rc_pay_num_li = $(".rc_pay_num li");
    var rc_u_money = $(".rc_u_money");
    rc_pay_num.html(tpl);
    $(".rc_pay_num li").eq(0).addClass("active");
    rc_u_money.html(rc_pay_num.find(".active").data("c_sort")+"元");

    $(".rc_pay_num li").on("click",function(){
        $(this).addClass("active").siblings("li").removeClass("active");
        rc_u_money.html($(this).data("c_sort")+"元");
    });

});

var paySubmit = $(".paySubmit");

var submitOk = function(){
    var c_sort = rc_pay_num.find(".active").data("c_sort");
    var c_value = rc_pay_num.find(".active").data("c_value");
    var c_id = rc_pay_num.find(".active").data("c_id");
    var param = {
        url:'Recharges/pay',
        data:{
            type:$("input[name=pay_list]:checked").val(),
            cid:c_id,
            amount:c_sort
        }
    };
    $.JsonRpc(param,function(data){
        console.log(data.data);
    //    线上调用
    });

};


paySubmit.on("click",submitOk);





















